package ui;
import java.awt.BorderLayout;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.JScrollPane;

import javax.swing.JTextArea;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import dto.LineBillDTO;
import dto.LineDTO;
import dto.PlanDTO;
import dto.PlanItemDTO;
import dto.ServiceDTO;
import dto.UserDTO;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class GenericView extends javax.swing.JFrame {
	private JTextArea jTextAreaBill;
	private UserDTO user;
	private PlanDTO plan;
	private LineDTO line;
	private ArrayList<ServiceDTO> services;
	private ArrayList<PlanDTO> plans;
	private JScrollPane jScrollPane1;
	private JScrollPane srollPanel; 
	private ArrayList<UserDTO> users;
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				GenericView inst = new GenericView();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public GenericView() {
		super();
	}
	public GenericView(UserDTO user) {
		super();
		this.user = user;
		initUserGUI();
		
	}
	public GenericView(PlanDTO plan) {
		super();
		this.plan = plan;
		initPlanGUI();
		
	}
	public GenericView(LineDTO line) {
		super();
		this.line = line;
		initLineGUI();
		
	}	
	public GenericView(ArrayList<ServiceDTO>  services) {
		super();
		this.services = services;
		initServiceGUI();
		
	}
	
	public GenericView(ArrayList<UserDTO> users, boolean client) {
		super();
		this.users = users;
		initUsersGUI();
	}

	private void initUsersGUI(){
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{	
				jTextAreaBill = new JTextArea();
				srollPanel = new JScrollPane(jTextAreaBill); 
				for (UserDTO client:users){
					
					//getContentPane().add(jTextAreaBill, BorderLayout.CENTER);
					getContentPane().add(srollPanel, BorderLayout.CENTER);
					jTextAreaBill.append("-------------User Start----------------"+"\n");
					jTextAreaBill.append("DNI: "+client.getDni()+"\n");
					jTextAreaBill.append("Apellido: "+client.getApellido()+"\n");
					jTextAreaBill.append("Nombre: "+client.getNombre()+"\n");
					jTextAreaBill.append("Domicilio: "+client.getDomicilio()+"\n");
					jTextAreaBill.append("Email: "+client.getEmail()+"\n");
					jTextAreaBill.append("------------User Lines-----------------"+"\n");
					for (LineDTO details : client.getLines()) {
						jTextAreaBill.append("Linea Numero: "+details.getNumber()+"\n");
						jTextAreaBill.append("Creada: "+details.getCreationDate()+"\n");					
						jTextAreaBill.append("-----------------------------"+"\n");
					}
					jTextAreaBill.append("-------------User End----------------"+"\n");
				}
			}
			pack();
			setSize(400, 300);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	private void initUserGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			pack();
			setSize(400, 300);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	private void initPlanGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{
				jTextAreaBill = new JTextArea();
				srollPanel = new JScrollPane(jTextAreaBill); 
				//getContentPane().add(jTextAreaBill, BorderLayout.CENTER);
				getContentPane().add(srollPanel, BorderLayout.CENTER);
				jTextAreaBill.append("Numero: "+plan.getPlanNumber()+"\n");
				jTextAreaBill.append("Description: "+plan.getPlanDescription()+"\n");
				jTextAreaBill.append("Costo: "+plan.getPlanCost()+"\n");
				jTextAreaBill.append("Descuento: "+plan.getDiscount()+"\n");
				for (PlanItemDTO details : plan.getPlanItems()) {
					jTextAreaBill.append("Service Name: "+details.getServiceName()+"\n");
					jTextAreaBill.append("Service Excess Cost: "+details.getServiceCost()+"\n");
					jTextAreaBill.append("Free Units: "+details.getServiceFreeUnits()+"\n");
					jTextAreaBill.append("-----------------------------"+"\n");
				}
				
			}
//			{
//				jTextAreaBill = new JTextArea();
//				srollPanel = new JScrollPane(jTextAreaBill); 
//				srollPanel = new JScrollPane(jTextAreaBill); 
//				//getContentPane().add(jTextAreaBill, BorderLayout.CENTER);
//				getContentPane().add(srollPanel, BorderLayout.CENTER);
//
//				{
//					jTextAreaBill = new JTextArea();
//					
//					jTextAreaBill.append("DNI: "+user.getDni()+"\n");
//					jTextAreaBill.append("Apellido: "+user.getApellido()+"\n");
//					jTextAreaBill.append("Nombre: "+user.getNombre()+"\n");
//					jTextAreaBill.append("Domicilio: "+user.getDomicilio()+"\n");
//					jTextAreaBill.append("Email: "+user.getEmail()+"\n");
//					for (LineDTO details : user.getLines()) {
//						jTextAreaBill.append("Linea Numero: "+details.getNumber()+"\n");
//						jTextAreaBill.append("Creada: "+details.getCreationDate()+"\n");					
//						jTextAreaBill.append("-----------------------------"+"\n");
//					}
//
//					
//				}
//			}
			pack();
			setSize(400, 300);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	private void initLineGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{
				jTextAreaBill = new JTextArea();
				srollPanel = new JScrollPane(jTextAreaBill); 
				//getContentPane().add(jTextAreaBill, BorderLayout.CENTER);
				getContentPane().add(srollPanel, BorderLayout.CENTER);
				jTextAreaBill.append("Numero: "+line.getNumber()+"\n");
				jTextAreaBill.append("Dni Cliente: "+line.getUserDNI()+"\n");
				jTextAreaBill.append("Nombre Cliente: "+line.getUserLastName()+", " +
						""+line.getUserName()+"\n");
				jTextAreaBill.append("Creada el:  "+line.getCreationDate()+"\n");
				jTextAreaBill.append("Credito:  "+line.getCredit()+"\n");
				for (LineBillDTO lineBillDTO : line.getBills()) {
					//for (String details : lineBillDTO.getBillDetails()) {
						//jTextAreaBill.append(details+"\n");
					//}
					jTextAreaBill.append(lineBillDTO.getBillDetails()+"\n");
					jTextAreaBill.append("Cost : "+lineBillDTO.getTotalCost() +"\n");
					jTextAreaBill.append("-----------------------------"+"\n");
				}
				
			}
			pack();
			setSize(400, 300);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	private void initServiceGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{
				jTextAreaBill = new JTextArea();
				srollPanel = new JScrollPane(jTextAreaBill); 
				//getContentPane().add(jTextAreaBill, BorderLayout.CENTER);
				getContentPane().add(srollPanel, BorderLayout.CENTER);

				jTextAreaBill.append("Servicios: "+"\n");
				for (ServiceDTO service  : services) {
					jTextAreaBill.append("Name: "+service.getServiceName()+"\n");
					jTextAreaBill.append("Units: "+service.getServiceUnit()+"\n");
					jTextAreaBill.append("-----------------------------"+"\n");
				}
//				
			}
			pack();
			setSize(400, 300);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
